package com.qf.controller;

import com.qf.pojo.entity.TbUser;
import com.qf.pojo.request.TbUserReq;
import com.qf.pojo.response.BaseResponse;
import com.qf.service.TbUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "用户控制器")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    TbUserService tbUserService;

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有用户信息")
    public BaseResponse findAll(@RequestParam("page")Integer page,@RequestParam("size")Integer size){
        return tbUserService.findAll(page, size);
    }
    /**
     * 修改|新增
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "增加或修改用户")
    public BaseResponse saveOrUpdate(@RequestBody TbUserReq tbUserReq){
        return tbUserService.saveOrUpdate(tbUserReq);
    }
    /**
     * 删除用户
     */
    @RequestMapping("deleteByUid")
    @ApiOperation(value = "删除用户")
    public BaseResponse deleteByUid(@RequestBody Map map){
        return tbUserService.delById(Integer.valueOf(map.get("uid").toString()));
    }

}
